package pe.com.tma.service;

import java.util.List;

import javax.annotation.security.RolesAllowed;

import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import pe.com.tma.dao.AuthenticationDAO;
import pe.com.tma.dao.CotizacionDAO;
import pe.com.tma.dao.DAOFactory;
import pe.com.tma.model.Usuario;

@Service("usuarioService")
public class AuthenticationService implements UserDetailsService{
	
	DAOFactory fabrica=DAOFactory.getDAOFactory(1);
	AuthenticationDAO dao = fabrica.getAuthenticationDAO();

	

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {
		Usuario usuario = null;
		List<Usuario> usuarios = dao.buscarUsuarioPorCodigo(username);
		if(usuarios.size()==0)throw new UsernameNotFoundException("Usuario no existe.");
		else{
			usuario = usuarios.get(0);
			//usuario.setPerfiles(dao.buscarPerfilesDeUsuarioPorCodigo(username));
	   return (UserDetails) usuario;
	   
	  }
	}

	public boolean login(String login, String password) {
		// TODO Auto-generated method stub
		return false;
	}
}
